<template>
  <div class="order-management">
    <el-card>
      <template #header>
        <span>费用订单管理</span>
      </template>

      <el-table :data="orders" style="width: 100%">
        <el-table-column prop="orderNum" label="订单号" width="200"/>
        <el-table-column prop="id" label="学号"/>
        <el-table-column prop="dormitory" label="宿舍楼"/>
        <el-table-column prop="roomNum" label="房间号"/>
        <el-table-column prop="totalAmount" label="金额">
          <template #default="scope">
            ¥{{ scope.row.totalAmount }}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="状态">
          <template #default="scope">
            <el-tag :type="scope.row.type === '已支付' ? 'success' : 'warning'">
              {{ scope.row.type }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="orderTime" label="创建时间">
          <template #default="scope">
            {{ formatDate(scope.row.orderTime) }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import {ref, onMounted} from 'vue'
import request from '../../utils/request'

const orders = ref([])

const formatDate = (dateString) => {
  return new Date(dateString).toLocaleString()
}

const loadOrders = async () => {
  try {
    const response = await request.get('/api/order/list')
    if (response.data.code === 200) {
      orders.value = response.data.data
    }
  } catch (error) {
    console.error('加载订单数据失败:', error)
  }
}

onMounted(() => {
  loadOrders()
})
</script>

<style scoped>
.order-management {
  padding: 0;
}
</style>
